package wjh.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import wjh.pojo.Plan;
import wjh.pojo.PlanVo;
import wjh.service.PlanService;

import java.sql.SQLException;
import java.util.List;

/**
 * 功能
 * 作者：lyh
 * 日期：2024/9/3 10:02
 */
@Controller
@RequestMapping("/plan")
public class PlanController {
    @Autowired
    private PlanService planService;
    //查找所有排班信息
    @RequestMapping("/findAllPai")
    public String findAllPai(
             //当前页
             @RequestParam(required = false,defaultValue = "1")Integer pageNum,
             //默认展示三条
             @RequestParam(required = false,defaultValue = "3")Integer pageSize,
             Model model,String likeName){
        //处理分页
        PageHelper.startPage(pageNum,pageSize);
        List<PlanVo> planList=null;
        if (likeName==null||likeName.trim()==""){
            planList = planService.findAllPai();
        }else {
            planList = planService.findAllPaiLike(likeName);
        }
        //得到pageInfo对象
        PageInfo<PlanVo> pageInfo = new PageInfo<>(planList);
        model.addAttribute("page",pageInfo);
        model.addAttribute("likeName",likeName);
        return "plan";
        }

    //查找所有排班信息
    @RequestMapping("/findAllPai2")
    public String findAllPai2(
            //当前页
            @RequestParam(required = false,defaultValue = "1")Integer pageNum,
            //默认展示三条
            @RequestParam(required = false,defaultValue = "3")Integer pageSize,
            Model model,String likeName){
        //处理分页
        PageHelper.startPage(pageNum,pageSize);
        List<PlanVo> planList=null;
        if (likeName==null||likeName.trim()==""){
            planList = planService.findAllPai();
        }else {
            planList = planService.findAllPaiLike(likeName);
        }
        //得到pageInfo对象
        PageInfo<PlanVo> pageInfo = new PageInfo<>(planList);
        model.addAttribute("page",pageInfo);
        model.addAttribute("likeName",likeName);
        return "doctor_plan";
    }
}
